#include "EditorCPUTimeAnalyzePageViewModel.h"

#include "Time/CPUTimeCounter.h"
#include "Asset/EngineDefaultPackage.h"

void REditorCPUTimeAnalyzePageViewModel::BindModel(TSharedObjectPtr<REditorPageModel> InModel)
{
    Super::BindModel(InModel);
    Model =InModel;

    //TODO 找个更合适的图标
    Icon= REngineDefaultPackage::Get()->GetEngineIcon();
}

TSharedObjectPtr<RTexture2D> REditorCPUTimeAnalyzePageViewModel::GetIcon() const
{
    return Icon;
}

CString REditorCPUTimeAnalyzePageViewModel::GetTitle() const
{
    return U"处理器(CPU)性能分析";
}

void REditorCPUTimeAnalyzePageViewModel::Start()
{
    if (CanStart())
    {
        CCPUTimeCounter::Get()->BeginTimeCount();
    }
}

bool REditorCPUTimeAnalyzePageViewModel::CanStart() const
{
    return CCPUTimeCounter::Get()->GetState()== CCPUTimeCounter::EState::Idle;
}

void REditorCPUTimeAnalyzePageViewModel::Stop()
{
    if (CanStop())
    {
        auto Result= CCPUTimeCounter::Get()->EndTimeCount();
        CCPUTimeCounter::Get()->PrintTimeCountResult(Result,2);
    }
}

bool REditorCPUTimeAnalyzePageViewModel::CanStop() const
{
    return CCPUTimeCounter::Get()->GetState()== CCPUTimeCounter::EState::TimeCounting;
}

CString REditorCPUTimeAnalyzePageViewModel::GetStateText() const
{
    switch(CCPUTimeCounter::Get()->GetState())
    {
    case CCPUTimeCounter::EState::Idle:
        return U"空闲";
    case CCPUTimeCounter::EState::TimeCounting:
        return U"正在统计...";
    case CCPUTimeCounter::EState::Finishing:
        return U"结束中...";
    default:
        return U"未知";
    }
}
